<?php


namespace app\http\middleware;

use app\common\model\OperateLog;
use app\Request;


class AdminLog
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle(Request $request, \Closure $next,$name)
    {
        $response = $next($request);
        $url ='/'. $request->rule()->getRule();
        $data =
            [
                'operate_id' => $request->staff_account['id'],
                'route' => $url,
                'name' => $name,
                'method' => $request->method(),
                'req_data' => json_encode($request->param()),
                'create_time' => time(),
                'ip' => $request->ip(),
            ];
        $operateLogModel = new OperateLog();
        $operateLogModel->insert($data);


        return $response;
    }
}